/*    */ package com.cr.framework.shiro.web.filter.online;
/*    */ 
/*    */ import com.cr.common.core.domain.entity.SysUser;
/*    */ import com.cr.common.enums.OnlineStatus;
/*    */ import com.cr.common.utils.ShiroUtils;
/*    */ import com.cr.framework.shiro.session.OnlineSession;
/*    */ import com.cr.framework.shiro.session.OnlineSessionDAO;
/*    */ import java.io.IOException;
/*    */ import javax.servlet.ServletRequest;
/*    */ import javax.servlet.ServletResponse;
/*    */ import org.apache.shiro.session.Session;
/*    */ import org.apache.shiro.subject.Subject;
/*    */ import org.apache.shiro.web.filter.AccessControlFilter;
/*    */ import org.apache.shiro.web.util.WebUtils;
/*    */ import org.springframework.beans.factory.annotation.Value;
/*    */ 
/*    */ public class OnlineSessionFilter extends AccessControlFilter {
/*    */   @Value("${shiro.user.loginUrl}")
/*    */   private String loginUrl;
/*    */   
/*    */   private OnlineSessionDAO onlineSessionDAO;
/*    */   
/*    */   protected boolean isAccessAllowed(ServletRequest request, ServletResponse response, Object mappedValue) throws Exception {
/* 40 */     Subject subject = getSubject(request, response);
/* 41 */     if (subject == null || subject.getSession() == null)
/* 43 */       return true; 
/* 45 */     Session session = this.onlineSessionDAO.readSession(subject.getSession().getId());
/* 46 */     if (session != null && session instanceof OnlineSession) {
/* 48 */       OnlineSession onlineSession = (OnlineSession)session;
/* 49 */       request.setAttribute("online_session", onlineSession);
/* 51 */       boolean isGuest = (onlineSession.getUserId() == null || onlineSession.getUserId().longValue() == 0L);
/* 52 */       if (isGuest == true) {
/* 54 */         SysUser user = ShiroUtils.getSysUser();
/* 55 */         if (user != null) {
/* 57 */           onlineSession.setUserId(user.getUserId());
/* 58 */           onlineSession.setLoginName(user.getLoginName());
/* 59 */           onlineSession.setAvatar(user.getAvatar());
/* 60 */           onlineSession.setDeptName(user.getDept().getDeptName());
/* 61 */           onlineSession.markAttributeChanged();
/*    */         } 
/*    */       } 
/* 65 */       if (onlineSession.getStatus() == OnlineStatus.off_line)
/* 67 */         return false; 
/*    */     } 
/* 70 */     return true;
/*    */   }
/*    */   
/*    */   protected boolean onAccessDenied(ServletRequest request, ServletResponse response) throws Exception {
/* 79 */     Subject subject = getSubject(request, response);
/* 80 */     if (subject != null)
/* 82 */       subject.logout(); 
/* 84 */     saveRequestAndRedirectToLogin(request, response);
/* 85 */     return false;
/*    */   }
/*    */   
/*    */   protected void redirectToLogin(ServletRequest request, ServletResponse response) throws IOException {
/* 92 */     WebUtils.issueRedirect(request, response, this.loginUrl);
/*    */   }
/*    */   
/*    */   public void setOnlineSessionDAO(OnlineSessionDAO onlineSessionDAO) {
/* 97 */     this.onlineSessionDAO = onlineSessionDAO;
/*    */   }
/*    */ }


/* Location:              D:\tmp\creditorRights-admin\BOOT-INF\lib\creditorRights-framework-4.7.0.jar!\com\cr\framework\shiro\web\filter\online\OnlineSessionFilter.class
 * Java compiler version: 8 (52.0)
 * JD-Core Version:       1.1.3
 */